﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Sheeps;

namespace SheepsWinFormsInterface
{
    public partial class FormDisplay : Form
    {
        Game game;
        ManualOverrideDogBehavior dogBehavior;

        public FormDisplay()
        {
            InitializeComponent();
        }

        private void canvasPanel_Paint(object sender, PaintEventArgs e)
        {
            if (this.game == null || this.game.State == null || this.game.State.SheepList == null)
            {
                return;
            }

            int x = 0;
            int y = 0;

            foreach (var sheep in this.game.State.SheepList)
            {
                x = (int)Math.Round(sheep.Position.X) - 5;
                y = (int)Math.Round(sheep.Position.Y) - 5;
                e.Graphics.DrawRectangle(Pens.White, x, y,
                    10, 10);
            }

            x = (int)Math.Round(this.game.State.Dog.Position.X) - 5;
            y = (int)Math.Round(this.game.State.Dog.Position.Y) - 5;
            e.Graphics.FillRectangle(Brushes.Black, x, y,
                10, 10);


        }

        private void generateButton_Click(object sender, EventArgs e)
        {
            this.dogBehavior = new ManualOverrideDogBehavior();
            this.game = new Game(dogBehavior, new MxSheepBehavior(), new RandomSheepGenerator(), canvasPanel.Width, canvasPanel.Height);
            this.game.GenerateSheep(1000);
            this.canvasPanel.Invalidate();
        }

        private void FormDisplay_Load(object sender, EventArgs e)
        {

        }

        private void canvasPanel_MouseUp(object sender, MouseEventArgs e)
        {
            this.dogBehavior.X = e.X;
            this.dogBehavior.Y = e.Y;
            this.game.NextStep();
            canvasPanel.Invalidate();
        }
    }
}
